import React from 'react'
// ===================================================================== Temp
import FormModal from '#cpt/temp/FormModal'
/* 修改相关操作说明 20211009  --耿琰 */
import Asks from '#tp/asks'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 			= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== private component
const ImportFile 	= $Lazy.load(()=>import('#private/common/import'))
// ===================================================================== data
const BoolStatus = [{ name:'是', value: '1', tip:Asks.ThirdPutaway }, { name:'否', value:'0' }]
const BoxStatus = [{ name:'是', value: '1', tip:Asks.ThirdHospital }, { name:'否', value:'0' }]
/* 添加相关说明 2021-09-27  --耿琰  20211009 修改 */
const CheckedStatus = [{ name:'未审核', value:'0', tip:Asks.SpecUnreviewed },{ name:'已审核', value:'1', tip:Asks.Audited  }]
// ===================================================================== component

class Index extends React.Component{
	state = {
		data: [],
		// 绑定三方条码
		formData:[
			{ label:'项目清单',		name: 'checked_spec', 		type: 'radio', 	full:true, 	value:'1', data:CheckedStatus },
			{ label:'开启第三方上架',	name: 'third_open_shelf', 	type: 'radio', 	full:true, 	value:'0', data:BoolStatus },
			{ label:'第三方医院',	name: 'third_hosp_id',		type:'select',	full:true,	loading:true },
			// 导入添加选择标本箱 2021-9-26  --马婷
			{ label:'是否选择导入标箱',name: 'is_box_code', 	type: 'radio', 	full:true, 	value:'0', data:BoxStatus,
				onValue:({value,formData})=>{
					if (value === '1'){
						$fn.hideRows(formData,['box_id'], false)
					}else{
						$fn.hideRows(formData,['box_id'], true)
					}
					this.setState({formData})
				}
			},
			{ label: '标本箱号',		name: 'box_id',	full:true,	type: 'select',	hide:true,	loading:true, nameStr:'box_code'},
		],
	}
	submit = {}
	
	open = ()=> {
		$fn.hideRows(this.state.formData,['box_id'], true)
		this.formRef.setValue({third_open_shelf:'0',checked_spec: '1', is_box_code: '0'})
		this.modal.open({formRef: this.formRef})
		this.getModalSelect()
	}
	
	// 弹窗获取下拉数据
	getModalSelect = async () => {
		const { formData } = this.state
		$cache.then( async f => {
			// 医院
			$fn.setRow( formData, 'third_hosp_id', await f.getCache({ api:'hospital' }) )
			//标本箱号
			$fn.setRow( formData, 'box_id', await f.getCache({ api:'box/select',param:{status:[82,83],limit:1000},way:'post',refresh:true}) )

			this.setState({ formData })
		})
	}
	
	render(){
		return	FormModal.call(this,{ title:'项目导入', labelWidth:'s10', width:600, api:'specimen/import', noOk:true,
			btnSuffix: (
				<ImportFile 
					api			= 'specimen/import' 
					btnConfig	= {{size:'middle', className:'ml20', ghost:false}}
					onQuery		= { () => {
						return this.formRef.getValue(true)
					} }
					onOk	= {({code})=>{		 // 文件导入异步 2021-9-10 10:50:52  --马婷 
						if(+code === 100 ){
							window.onRefresh = () => {
								this.props.onRefresh()
								this.modal.close()
							}
						}else{
							this.props.onRefresh()
							this.modal.close()
						}
					}}
				/>
			)
		})
	}
}
 //  2021-8-23 2:29:12 ?F10: PM? --伍智睿
export default Index